<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class ThamSoService {

    public static function add($key, $value) {
        return ThamSo::model()->save(array('Key' => $key, 'Value' => $value));
    }

    public static function getAll() {
        return ThamSo::model()->findAll();
    }

    public static function getById($Id) {
        return ThamSo::model()->findByPk($Id);
    }

    public static function getByKey($key) {
        return ThamSo::model()->findByAttributes(array('Key' => $key));
    }

    public static function updateById($id, $key, $value) {
        return ThamSo::model()->updateByPk($id, array('Key' => $key, 'Value' => $value));
    }

    public static function update($id, $param) {
        $ts = ThamSoService::getById($id);
        isset($param['Key']) ? $ts->Key = $param['Key'] : 1;
        isset($param['Value']) ? $ts->Value = $param['Value'] : 1;
        return $ts->update();
    }

}
